package com.my.aslife.controller;


import com.my.aslife.module.common.Condition;
import com.my.aslife.module.common.ErrorCode;
import com.my.aslife.module.common.PageRequestVo;
import com.my.aslife.module.common.ResponseResult;
import com.my.aslife.module.entity.RunnerDetail;
import com.my.aslife.module.entity.dtos.DemandAcceptDto;
import com.my.aslife.module.entity.dtos.RunnerDetailAllowDto;
import com.my.aslife.service.IRunnerDetailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2022-12-12
 */
@RestController
@RequestMapping("/api/my/runner-detail")
@CrossOrigin
@Slf4j
public class RunnerDetailController {

    @Autowired
    private IRunnerDetailService runnerDetailService;

    @GetMapping("/apply/runner/list")
    public ResponseResult getUserIllegalByPage(@RequestParam Integer current, @RequestParam Integer pageSize,
                                               @RequestParam(value = "phone", required = false) String phone,
                                               @RequestParam(value = "email", required = false) String email) {

        Condition condition = new Condition(phone, email);
        PageRequestVo pageRequestVo = new PageRequestVo(current, pageSize, condition);
        log.info("查询条件 condition ==> {}", condition);

        return runnerDetailService.getUserIllegalByPage(pageRequestVo);
    }

    @PostMapping("/apply/msg/{uid}")
    public ResponseResult queryRunnerDetailInfoByUID(@PathVariable Long uid) {
        return runnerDetailService.queryRunnerDetailInfoByUID(uid);
    }

    @PostMapping("/upload/runner")
    public ResponseResult uploadApplyRunnerImg(MultipartFile file) {
        if (file == null) {
            return ResponseResult.failed(ErrorCode.ILLEGAL_OPERATOR);
        }

        return runnerDetailService.uploadApplyRunnerImg(file);
    }

    @PostMapping("/list/{uid}")
    public ResponseResult queryRunnerDetailByUID(@PathVariable Long uid) {
        return runnerDetailService.queryRunnerDetailByUID(uid);
    }

    @PostMapping("/commit/{uid}")
    public ResponseResult commitApply(@PathVariable Long uid) {
        return runnerDetailService.commitApply(uid);
    }

    @PostMapping("/allow/into/runner")
    public ResponseResult allowIntoRunner(@RequestBody RunnerDetailAllowDto runnerDetailAllowDto) {
        return runnerDetailService.allowIntoRunner(runnerDetailAllowDto);
    }

    @PostMapping("/apply/fail")
    public ResponseResult applyRunnerFail(@RequestBody RunnerDetail runnerDetail) {
        return runnerDetailService.applyRunnerFail(runnerDetail);
    }

    @PostMapping("/apply/ok")
    public ResponseResult applyRunnerOK(@RequestBody RunnerDetail runnerDetail) {
        return runnerDetailService.applyRunnerOK(runnerDetail);
    }

    @PostMapping("/run/ok/{orderId}")
    public ResponseResult runOk(@PathVariable Long orderId) {
        return runnerDetailService.runOk(orderId);
    }
}
